/*
 * @Description: 模拟网络请求得到的数据
 * @Author: CcSimple
 * @Github: https://github.com/CcSimple
 * @Date: 2023-04-02 15:14:15
 * @LastEditors: CcSimple
 * @LastEditTime: 2023-04-02 15:47:33
 */
import { GetTempProviderByName } from "@/util/request"
// 配合 provider-helper.js 使用
let Pdata = {
  key: "NetProvider1",
  options: {
    groupName: "NetProvider1分组名称",
    printElements: [
      {
        id: "tableCustom",
        type: "tableCustom",
        title: "默认表格",
        field: "table",
        options: {},
        columns: [
          [
            { title: "姓名", align: "center", field: "Name", width: 100 },
            { title: "性别", align: "center", field: "Sex", width: 100 },
          ],
        ],
      },
    ],
  },
};

export const DealData = async (tempName) => {
  try {
    const parm = { TemplateName: tempName };
    const dt = await GetTempProviderByName(parm);

    let elements = [];
    let cols=[];
    dt.forEach(sources => {
      if (sources.Colums) {
        sources.Colums.forEach(col => {
          let el = {
            id: "providerModule1." + col.filed,
            type: "text",
            title: col.name,
            field: col.filed,
            options: {
            }
          };
          elements.push(el);
          cols.push({ title: col.name, align: "center", field: col.filed })
        })

        let dtable={
          id: "tableCustom",
          type: "tableCustom",
          title: "默认表格",
          field: sources.Group,
          options: {},
          columns: [cols]
        }
       console.log(cols)
        elements.push(dtable)
      }
    });

   

    Pdata.options.printElements=elements; 
  }
  catch (e) {
    console.log(e)
  }
  return Pdata;
}

//export default data;
